const Parser = require("jison").Parser;
const fs = require("fs-extra");
const path = require("path");
const grammer = require("./grammer");

const parser = new Parser(grammer);
const parserSource = parser.generate();

const source = `var types = require('../types');\n var Operator = types.Operator;\n var BoolOperation = types.BoolOperation;\n` + parserSource;

const targetDir = path.join(__dirname, '../../lib/parser/');

fs.outputFileSync(path.join(__dirname, "./parser.js"), source);
fs.ensureDirSync(targetDir);

[
  './parser.js',
  './parser.d.ts',
].forEach(fileName => {
  fs.copySync(path.join(__dirname, fileName), path.join(targetDir, fileName));
});
